package com.eece496.Server;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.eece496.Database.TAduties;
import com.eece496.Helpers.TADutiesInfo;

/**
 * Servlet implementation class TAViewAssessmentsServlet
 */
public class TAViewAssessmentsServlet extends MasterServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TAViewAssessmentsServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Connect();
		String firstname = request.getParameter("firstname");
		String lastname = request.getParameter("lastname");
		String courseNumber = request.getParameter("courseNumber");
		String sectionNumber = request.getParameter("sectionNumber");
		String tID = request.getParameter("TAID");
		int TAID = Integer.parseInt(tID);
		String empty = "empty";
		
		
		System.out.println(tID);
		
		
		//Create an ArrayLis to Divisions
		ArrayList<String> divisions = new ArrayList<String>();
		//Create an ArrayList hold all the TA info
		ArrayList<ArrayList<TADutiesInfo>> TAInfo = new ArrayList<ArrayList<TADutiesInfo>>();
		
		TAduties TADutiesDB = new TAduties();
		TADutiesDB.Setup(connection);
		
		try {

			//Get incomplete info
			ArrayList<TADutiesInfo> info = new ArrayList<TADutiesInfo>();
			info = TADutiesDB.GetTADuties(TAID, courseNumber, sectionNumber, "incomplete");
			System.out.println("THE SIZE OF THE INCOMPLETE LIST IS: " +info.size());
			
			//get complete duties
			ArrayList<TADutiesInfo> cinfo = new ArrayList<TADutiesInfo>();
			cinfo = TADutiesDB.GetTADuties(TAID, courseNumber, sectionNumber, "complete");
			
			
			request.setAttribute("divisions", divisions);
			request.setAttribute("TADutyInfo", info);
			request.setAttribute("CompleteInfo", cinfo);
			request.setAttribute("firstname", firstname);
			request.setAttribute("lastname", lastname);
			request.setAttribute("courseNumber", courseNumber);
			request.setAttribute("sectionNumber", sectionNumber);
			request.setAttribute("TAID", tID);
			request.setAttribute("empty", empty);
			request.getRequestDispatcher("/TA/TA-View-Assessments.jsp")
					.forward(request, response);
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
